package com.sxt.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.sxt.common.Constant;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:
 * @author: Mr.T
 * @date 2020-11-03 14:55
 */
@WebServlet("/checkCode.do")
public class CheckCodeServlet extends HttpServlet {


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //产生验证码对象
        LineCaptcha code = CaptchaUtil.createLineCaptcha(78, 36, 4, 10);
        //将验证码字符串放入session
        String code1 = code.getCode();
        req.getSession().setAttribute(Constant.CHECK_CODE_KEY,code1);
        //输出验证码
        code.write(resp.getOutputStream());
    }
}
